//
//  SinaTabBarViewController.swift
//  weibo
//
//  Created by sirius on 15/12/30.
//  Copyright © 2015年 sirius. All rights reserved.
//

import UIKit

class SinaTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //先获取当前的tabbar,然后设置tintcolor(选中的颜色)
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        //添加子控制器
        addChildViewController()
        
        //改变系统的tabbar
        let tabbar = SinaTabBar()
        //tabBar 只读的
        //用KVC  只读属性赋值
        setValue(tabbar,forKeyPath: "tabBar")
//        tabBar = tabbar
        tabbar.composeButton.addTarget(self, action: "publish", forControlEvents: UIControlEvents.TouchUpInside)
        
       
    }
    //MARK: --发布微博按钮的点击
    func publish(){
        printLog("发布界面")
//        SinaNewFeatureCollectionViewController()
        presentViewController(SinaNewFeatureCollectionViewController(), animated: true) { () -> Void in
             
        }
        
    }
    func addChildViewController() {
        addChildViewController(SinaHomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(SinaMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(SinaFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(SinaSettingViewController(), title: "设置", image: "tabbar_profile" )
        
    }
    //MARK:     抽象封装一个方法 重载
     func addChildViewController(childController: UIViewController,title: String,image: String) {
 
//        let home = SinaHomeViewController()
        childController.title  = title
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        let nav = UINavigationController(rootViewController:  childController)
        //添加到tabbar控制器
        addChildViewController(nav)

    
    }

}
